<?php

require_once dirname(__FILE__) . '/../lib/sfGuardUserGeneratorConfiguration.class.php';
require_once dirname(__FILE__) . '/../lib/sfGuardUserGeneratorHelper.class.php';

/**
 * sfGuardUser actions.
 *
 * @package    sfGuardPlugin
 * @subpackage sfGuardUser
 * @author     Fabien Potencier
 * @version    SVN: $Id: actions.class.php 23319 2009-10-25 12:22:23Z Kris.Wallsmith $
 */
class sfGuardUserActions extends autoSfGuardUserActions {

    public function executeIndex(sfWebRequest $request) {

        // sorting
        if ($request->getParameter('sort')) {
            $this->setSort(array($request->getParameter('sort'), $request->getParameter('sort_type')));
        }

        // pager
        if ($request->getParameter('page')) {
            $this->setPage($request->getParameter('page'));
        }

        /**
         * SuperAdmin poderão ver todos os registros
         * Usuáios Comuns poderão ver apenas o registro sobre si
         */
        $user = $this->getUser();
        if ($user->getGuardUser()->getIsSuperAdmin()) {
            //se SuperAdmin
            $this->pager = $this->getPager();
        } else {
            //se Usuário Normal
            $this->pager = $this->getPager();
            $this->pager->getQuery()->where('id = ?', $this->getUser()->getGuardUser()->getId());
        }

        $this->sort = $this->getSort();

        // has filters? (usefull for activate reset button)
        $this->hasFilters = $this->getUser()->getAttribute('sfGuardUser.filters', $this->configuration->getFilterDefaults(), 'admin_module');
    }

}
